// GraphicModelSpaceManager.cpp: implementation of the GraphicModelSpaceManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "GraphicModelSpaceManager.h"
#include "Project.h"
#include "Shlwapi.h"
#include "GraphicModelSpaceGenerator.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GraphicModelSpaceManager::GraphicModelSpaceManager()
{

}

GraphicModelSpaceManager::~GraphicModelSpaceManager()
{

}

void GraphicModelSpaceManager::AddGMS(GraphicModelSpace* pGMS)
{
	ASSERT(pGMS);
	ASSERT(GetManaged(pGMS->SpaceName()) == NULL);

	Add(pGMS->SpaceName(), pGMS);
}

GraphicModelSpace* GraphicModelSpaceManager::FindGMS(const CString& strGMSName)
{
	GraphicModelSpace* pGMS = GetManaged(strGMSName);
	if(pGMS != NULL)
		return pGMS;

	ASSERT(project());

	CString strFile = project()->PrjModelPath() + strGMSName + _T(".dwg");

	if(!PathFileExists(strFile))
	{
		return NULL;
	}

	pGMS = GraphicModelSpaceGenerator::Instance()
		->Generate(strFile);

	pGMS->SpaceName(strGMSName);
	pGMS->project(project());
	this->AddGMS(pGMS);

	return pGMS;
}

BOOL GraphicModelSpaceManager::IsOpen(const CString& strGMSName)
{
	if(GetManaged(strGMSName) == NULL)
		return FALSE;
	return FALSE;
}